package org.vy.dal.dao;

import org.vy.dal.QueryManager;
import org.vy.dal.seq.AddressSeqGenerator;

public class VyAddressDAO {
	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE ADDRESS_ID = m_AddressId";
	private static final String UPDATE = "UPDATE <TABLE> SET REF_ID = m_RefId, ADDRESS_TYPE = m_AddressType, NAME_PREFIX = m_NamePrefix, CO_NAME = m_CoName, STREET_1 = m_Street1, STREET_2 = m_Street2, STREET_HINDI_1 = m_StreetHindi1, STREET_HINDI_2 = m_StreetHindi2, DISTRICT_OR_COUNTY = m_DistrictOrCounty, CITY = m_City, STATE_OR_REGION = m_StateOrRegion, COUNTRY = m_Country, POST_BOX = m_PostBox, ZIP = m_Zip, PRINT_LANGUAGE = m_PrintLanguage, PHONE1 = m_Phone1, PHONE2 = m_Phone2, FAX = m_Fax, IS_DELETED = m_IsDeleted, EFFECTIVE_DATE = m_EffectiveDate, LAST_UPDATED_BY = m_LastUpdatedBy, LAST_UPDATED_ON = m_LastUpdatedOn WHERE ADDRESS_ID = m_AddressId";
	private static final String INSERT = "INSERT INTO <TABLE> (ADDRESS_ID,REF_ID,ADDRESS_TYPE,NAME_PREFIX,CO_NAME,STREET_1,STREET_2,STREET_HINDI_1,STREET_HINDI_2,DISTRICT_OR_COUNTY,CITY,STATE_OR_REGION,COUNTRY,POST_BOX,ZIP,PHONE1,PHONE2,FAX,IS_DELETED,EFFECTIVE_DATE,PRINT_LANGUAGE,LAST_UPDATED_BY,LAST_UPDATED_ON) VALUES (m_AddressId,m_RefId,m_AddressType,m_NamePrefix,m_CoName,m_Street1,m_Street2,m_StreetHindi1,m_StreetHindi2,m_DistrictOrCounty,m_City,m_StateOrRegion,m_Country,m_PostBox,m_Zip,m_Phone1,m_Phone2,m_Fax,m_IsDeleted,m_EffectiveDate,m_PrintLanguage,m_LastUpdatedBy,m_LastUpdatedOn)";
	private static final String DELETE = "UPDATE <TABLE> SET IS_DELETED = true WHERE ADDRESS_ID = m_AddressId";

	public static VyAddressDO findByPK(Integer key) throws Exception {
		VyAddressDO dto = new VyAddressDO();
		dto.setAddressId(key);
		dto = (VyAddressDO) QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}
	public static VyAddressDO insert(VyAddressDO dto) throws Exception {
		dto.setAddressId(Integer.parseInt(AddressSeqGenerator.getInstance().getNextSequence()));
		dto = (VyAddressDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyAddressDO update(VyAddressDO dto) throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static VyAddressDO delete(Integer key) throws Exception {
		VyAddressDO dto = new VyAddressDO();
		dto.setAddressId(key);
		boolean i = QueryManager.executeDelete(dto, DELETE);
		if (i == true)
			return dto;
		else
			return null;
	}

}
